package com.momo.hotel.utils;

import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;
import org.springframework.validation.ObjectError;

import java.util.List;

/**
 * @version 1.0.0
 * @auther Snake
 * @date 2019/6/20 19:49
 */
public class ValidationUtil {
    public static void assertValidation(BindingResult errors){
        if (errors.hasErrors()) {
            //变量所有异常信息
            List<ObjectError> errorList = errors.getAllErrors();
            for (ObjectError error : errorList) {
                FieldError fieldError = (FieldError) error;
                throw new RuntimeException(fieldError.getDefaultMessage());
            }
        }
    }
}
